package com.controller;

import com.services.IFlightServices;
import com.services.impl.FlightServicesImpl;
import net.sf.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Program: exam
 * @ClassName: FlightChangeSelectServletController
 * @Description: ${description}
 * @Author: li
 * @Create: 2024-12-23 20:57
 */
@WebServlet("/FlightChangeSelectServlet")
public class FlightChangeSelectServletController extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String _fids = request.getParameter("fids");
        int status = Integer.parseInt(request.getParameter("fstatus"));

        System.out.println(status);

        IFlightServices services = new FlightServicesImpl();

        String[] ids = _fids.split(",");

        for (String id : ids) {
            services.changeFlightStatus(Integer.parseInt(id),status);
        }
        Map<String,Object> map = new HashMap<>();
        map.put("code","0");
        String jsonResult = JSONObject.fromObject(map).toString();
        System.out.println("响应结果：" + jsonResult);
        response.getWriter().write(jsonResult);
    }
}
